package com.hrserviceserve.controller;

import com.hrserviceserve.entity.Result;
import com.hrserviceserve.entity.Training;
import com.hrserviceserve.service.TrainingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/training")
public class TrainingController {
    @Autowired
    TrainingService service;
    @GetMapping
    public Result findAll(@RequestParam("page") int page, @RequestParam("limit") int limit,
                          @RequestParam(value = "personnelId",required = false) Integer personnelId,
                          @RequestParam(value = "trainingCourse",required = false) String trainingCourse){
//        return Result.success();
        Map<String,Object> map=new HashMap<>();
        map.put("page", page);
        map.put("limit", limit);
        map.put("personnelId",personnelId);
        map.put("trainingCourse",trainingCourse);
        return service.findByPage(map);
    }
    @PostMapping
    public Result save(@RequestBody Training training){
        return service.save(training);
    }
    @DeleteMapping
    public Result delete(@RequestParam("id") int id){
         int i=service.delete(id);
         if (i>0){
             return Result.success();
         }else {
             return Result.fail();
         }
    }
}
